package com.yeswater.multithread.chapter1.test1_2.test1_2_9;

import java.util.concurrent.TimeUnit;

/**
 * author : yeswater
 * date : 2023/10/18
 */

public class LoginServlet {
    private static String usernameRef;
    private static String passwordRef;

    // 加 synchronized 解决线程安全问题
    synchronized public static void doPost(String username, String password) {
        try{
            usernameRef = username;
            if (username.equals("a")) {
                TimeUnit.SECONDS.sleep(5);
            }
            passwordRef = password;

            System.out.println("username : " + usernameRef + " password : " + password);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
